package com.test13;

import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalField;
import java.util.Calendar;

public class MyTest_03 {

    @Test
    public void test1() {
        double sin = Math.sin(Math.PI*30/180);
        System.out.println(sin);
    }

    @Test
    public void test2() {
        System.out.println(Math.round(15.1));
        System.out.println(Math.round(15.51));
        System.out.println(Math.round(-15.1));
        System.out.println(Math.round(-15.51));
    }

    @Test
    public void test3() {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.MONTH) + 1);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println(calendar.get(Calendar.HOUR_OF_DAY));
        System.out.println(calendar.get(Calendar.MINUTE));
        System.out.println(calendar.get(Calendar.SECOND));
    }

    @Test
    public void test4() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(calendar.get(Calendar.YEAR), 8, 1);
        calendar.add(Calendar.DATE, -1);
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.MONTH) + 1);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println(calendar.get(Calendar.HOUR_OF_DAY));
        System.out.println(calendar.get(Calendar.MINUTE));
        System.out.println(calendar.get(Calendar.SECOND));
    }

    @Test
    public void test5() {
        LocalDate localDate = LocalDate.now();
        LocalTime localTime = LocalTime.now();
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDate);
        System.out.println(localTime);
        System.out.println(localDateTime);
    }

    @Test
    public void test6() {
        LocalDate localDate = LocalDate.of(2022, 8, 9);
        System.out.printf("【当前日期】%s-%s-%s%n", localDate.getYear(), localDate.getMonth().getValue(), localDate.getDayOfMonth());
        System.out.println("星期几：" + localDate.getDayOfWeek().getValue());
        System.out.println("当月第几个星期：" + localDate.get(ChronoField.ALIGNED_WEEK_OF_MONTH));
        System.out.println("当年第几个星期：" + localDate.get(ChronoField.ALIGNED_WEEK_OF_YEAR));
        System.out.println("一年第几天：" + localDate.getDayOfYear());
        System.out.println("是否闰年：" + localDate.isLeapYear());
        System.out.println("=======================================");
        System.out.println("当月第一天：" + localDate.with(TemporalAdjusters.firstDayOfMonth()));
        System.out.println("当月第二天：" + localDate.withDayOfMonth(2));
        System.out.println("当月最后一天：" + localDate.with(TemporalAdjusters.lastDayOfMonth()));
    }
}
